/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "prs_FrmFiller.h"
#include "frm_filler_TNodeSolidLine.h"

using namespace prs;

// TRuleFrmFiller /////////////////////////////////////////////////////////////

//
TRuleFrmFiller::TRuleFrmFiller(
	snt::text::TContext &Context,
	svl::TVariant &VParentNode,
	svl::TVariant &VFiller
) 
:vFiller(VFiller)
,vParentNode(VParentNode)
,RColor(Context,vColor)
,RImage(Context,vImage,vType,VParentNode)
,RImageCenter(Context,vImage,VParentNode)
,RImageBorderOld(Context,vBorderImages,VParentNode)
,RImageBorder(Context,vBorderInfo,VParentNode)
,RLineHT(Context,vColor,vWeight)
,RLineHC(Context,vColor,vWeight)
,RLineHB(Context,vColor,vWeight)
,RLineVL(Context,vColor,vWeight)
,RLineVC(Context,vColor,vWeight)
,RLineVR(Context,vColor,vWeight)
{
	snt::TFVoid          F;
	snt::TReturn         Return;
	snt::text::TSequence T(Context);

	vThis = this;
	vColor = &color;
	vType  = imgType;
	
	this->Name(GetClassName())
	| T.New("filler") & F.New(FClear,vThis) & T.New("(") & A.New()
	;
	A.Name(GetClassName() + "[A]")
	| RColor.New()       & F.New(FColor,vThis)       & A.New()
	| RFrameRect.New()   & F.New(FFrameRect,vThis)   & A.New()
	| RRoundRect.New()   & F.New(FRoundRect2,vThis)  & A.New()
	| RImageBorderOld.New() & F.New(FImageBorderOld,vThis) & A.New() 
	| RImageBorder.New() & F.New(FImageBorder,vThis) & A.New() 
	| RImageCenter.New() & F.New(FImageCenter,vThis) & A.New()
	| RImage.New()	   & F.New(FImage,vThis)	   & A.New()
	| RTreeLine.New()    & F.New(FTreeLine,vThis)    & A.New()
	| RLineHT.New()	   & F.New(FLineHT,vThis)	   & A.New()
	| RLineHC.New()	   & F.New(FLineHC,vThis)	   & A.New()
	| RLineHB.New()	   & F.New(FLineHB,vThis)	   & A.New()
	| RLineVL.New()	   & F.New(FLineVL,vThis)	   & A.New()
	| RLineVC.New()	   & F.New(FLineVC,vThis)	   & A.New()
	| RLineVR.New()	   & F.New(FLineVR,vThis)	   & A.New()
	| T.New(")") & Return.New()
	;
	
	RFrameRect
	| T.New("frameRect") & T.New("=") & RColor.Rrgb.New() & Return.New()
	;

	RRoundRect
	| T.New("roundRect") & T.New("=") & RColor.Rrgb.New() & F.New(FRoundRect1,vThis) 
	& T.New("-") & RColor.Rrgb.New() & Return.New()
	;

	RTreeLine
	| T.New("treeLine") & T.New("=") & RColor.Rrgb.New() & Return.New()
	;
}

//
frm::filler::TFiller &TRuleFrmFiller::GetFiller()
{
	frm::filler::TFiller *P = dynamic_cast<frm::filler::TFiller*>(
		vFiller.Pointer()
	);
	
	if (!P) { 
		Except("GetFiller[!P]");
	}
	return *P;
}

//
void TRuleFrmFiller::FClear(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	R.GetFiller().SetNull(); 
	R.GetFiller().Set(frm::filler::TEmpty()); 
}

//
void TRuleFrmFiller::FColor(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	R.GetFiller().SetOrAdd(frm::filler::TColor(R.color)); 
}

//
void TRuleFrmFiller::FFrameRect(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	R.GetFiller().SetOrAdd(frm::filler::TFrameRect(R.color)); 
}

//
void TRuleFrmFiller::FImage(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	grf::TImageGdiP *image = dynamic_cast<grf::TImageGdiP*>(R.vImage.Pointer());
	
	if( R.vType.String() == "single" ){
		R.GetFiller().SetOrAdd( frm::filler::TImage( *image ) );
		return;
	}
	
	if( R.vType.String() == "fill" ){
		R.GetFiller().SetOrAdd( frm::filler::TFillImage( *image ) ); 
		return;
	}
}

//
void TRuleFrmFiller::FImageCenter(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	grf::TImageGdiP *image = dynamic_cast<grf::TImageGdiP*>(R.vImage.Pointer());
	
	R.GetFiller().SetOrAdd( frm::filler::TImageCenter( *image ) );

}

//
void TRuleFrmFiller::FImageBorderOld(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	grf::TImageGdiP **image =(grf::TImageGdiP**)(R.vBorderImages.Integer());
	
	R.GetFiller().SetOrAdd( frm::filler::TImageBorderOld( image ) );
}

//
void TRuleFrmFiller::FImageBorder(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	grf::TBorderInfo *bi =(grf::TBorderInfo*)(R.vBorderInfo.Integer());
	
	R.GetFiller().SetOrAdd( frm::filler::TImageBorder( bi ) );
}

//
void TRuleFrmFiller::FLineHT(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	R.GetFiller().SetOrAdd( frm::filler::TLineHorzTop( R.color.R
													 , R.color.G
													 , R.color.B
													 , R.vWeight.Integer()) );
}
//
void TRuleFrmFiller::FLineHC(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	R.GetFiller().SetOrAdd( frm::filler::TLineHorzCenter( R.color.R
														, R.color.G
														, R.color.B
														, R.vWeight.Integer()) );
}
//
void TRuleFrmFiller::FLineHB(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	R.GetFiller().SetOrAdd( frm::filler::TLineHorzBottom( R.color.R
														, R.color.G
														, R.color.B
														, R.vWeight.Integer()) );
}
//
void TRuleFrmFiller::FLineVL(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	R.GetFiller().SetOrAdd( frm::filler::TLineVertLeft( R.color.R
													  , R.color.G
													  , R.color.B
													  , R.vWeight.Integer()) );
}
//
void TRuleFrmFiller::FLineVC(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	R.GetFiller().SetOrAdd( frm::filler::TLineVertCenter( R.color.R
														, R.color.G
														, R.color.B
														, R.vWeight.Integer()) );
}
//
void TRuleFrmFiller::FLineVR(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	R.GetFiller().SetOrAdd( frm::filler::TLineVertRight( R.color.R
													   , R.color.G
													   , R.color.B
													   , R.vWeight.Integer()) );
}

//
void TRuleFrmFiller::FRoundRect1(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]);
	R.color2 = R.color;
}

//
void TRuleFrmFiller::FRoundRect2(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	R.GetFiller().SetOrAdd(frm::filler::TRoundRect(R.color, R.color2)); 
}

//
void TRuleFrmFiller::FTreeLine(snt::TParams &Params) 
{ 
	TRuleFrmFiller &R = GetThis(Params[0]); 
	R.GetFiller().SetOrAdd(frm::filler::TNodeSolidLine(R.color)); 
}